package com.itheima.ydd.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.dto.SysUserDto;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = 632228798L;

    private long count; //总记录数(总条数)
    private long totalPages; //总页数
    private long pageSize; //每页显示条数
    private long currentPage; //当前页
    private Object data; //封装的具体数据集合

    public PageResult() {
    }

    public PageResult(long count, long totalPages, long pageSize, long currentPage, Object data) {
        this.count = count;
        this.totalPages = totalPages;
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.data = data;
    }

    public static PageResult init(long count, long pageSize, long currentPage, Object data){
        long totalPages = count % pageSize == 0 ? count/pageSize : count/pageSize +1;
        return new PageResult(count,totalPages,pageSize,currentPage,data);

    }

    public static PageResult getPage(Page page){
        long totalPages = page.getTotal() % page.getSize() ==0 ? page.getTotal()/ page.getSize() : page.getTotal()/ page.getSize() + 1;
        return new PageResult(page.getTotal(),totalPages,page.getSize(),page.getCurrent(),page.getRecords());
    }
}
